package mvc.views.frames
{
	import alternativa.gui.controls.tree.TreeItemContainer;
	import alternativa.gui.data.DataProvider;
	import alternativa.gui.event.ListEvent;
	import alternativa.gui.theme.defaulttheme.container.list.List;
	import alternativa.gui.theme.defaulttheme.container.panel.Panel;
	import alternativa.gui.theme.defaulttheme.controls.tree.Tree;
	import alternativa.gui.theme.defaulttheme.controls.tree.TreeObject;
	
	import com.greensock.TweenNano;
	
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.net.sendToURL;
	import flash.utils.setTimeout;
	
	import globals.Config;
	import globals.Global;
	
	import interfaces.ILayoutAnimationFrame;
	
	import mvc.AppFacade;
	import mvc.Notifications;
	
	import utils.UtilsAnimation;
	import utils.UtilsUIManager;
	
	public class FrameAccessList extends Frame implements ILayoutAnimationFrame
	{
		private var _holderPanel:Panel;
		
		private var _tree:Tree;
		
		public function FrameAccessList()
		{
			super();
		}
		
		override protected function initUI():void
		{
			// TODO Auto Generated method stub
			super.initUI();

			_tree = UtilsUIManager.createTree(null,0,0,0,0);
			
			_tree.addEventListener(ListEvent.SELECT_ITEM,onSelect);
			

			_holderPanel = UtilsUIManager.createPanel(this,"管理功能",0,0,0,0,_tree);
			
			resize();
			
		}
		
		override public function show():void
		{
			// TODO Auto Generated method stub
			super.show();
			lock();
			
			var treeItemContainer:TreeItemContainer = (_tree.container as TreeItemContainer);
			var num:int = treeItemContainer.numChildren;
			var item:TreeObject = null;
			
			for(var i:int=0;i<num;++i)
			{
				item = treeItemContainer.getChildAt(i) as TreeObject;
				item.alpha = 0;
				item.locked=true;
				TweenNano.to(item,0.1,{alpha:1,delay:0.1*(i+1)});
			}
			_tree.selectedIndex = 0;
			setTimeout(unLock,num*100);
			
			
		}
		
		override public function update($model:Object):void
		{
			// TODO Auto Generated method stub
			super.update($model);
			_tree.dataProvider = $model as DataProvider;
		}
		
		public function select():void
		{
			
		}
		
		private function onSelect(evt:ListEvent):void
		{
			var treeItemContainer:TreeItemContainer = evt.target as TreeItemContainer;
			if(!treeItemContainer.selectedItem.hasChildren)
				AppFacade.getInstance().sendNotification(Notifications.MEDIATOR_SELECT_MAIN,{id:treeItemContainer.selectedItem.level});
		}
		
		
		override public function resize(evt:Event=null):void
		{
			// TODO Auto Generated method stub
			super.resize(evt);
			this.x = positionX;
			this.y = positionY;
			_holderPanel.resize(animationWidth,animationHeight);
		}
		
		public function get animationWidth():int
		{
			return 200;
		}
		
		public function get animationHeight():int
		{
			return Global.stageH-Config.bottomHeight-Config.headerHeight;
		}
		
		public function get positionX():int
		{
			// TODO Auto Generated method stub
			return 0;
		}
		
		public function get positionY():int
		{
			// TODO Auto Generated method stub
			return Config.headerHeight;
		}
		
		public function endAnimation():void
		{
			// TODO Auto Generated method stub
			
		}
		
		public function startAnimation():void
		{
			// TODO Auto Generated method stub
			
		}

		public function get holderPanel():Panel
		{
			return _holderPanel;
		}

		
		public function get offsetX():int
		{
			// TODO Auto Generated method stub
			return 0;
		}
		
		public function get offsetY():int
		{
			// TODO Auto Generated method stub
			return 0;
		}
		
		override public function lock():void
		{
			// TODO Auto Generated method stub
			super.lock();
		}
		
		override public function unLock():void
		{
			// TODO Auto Generated method stub
			super.unLock();
			_tree.locked=false;
		}
		
	}
}